home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / screen-resolution-extra / policy-dontzap.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  1.9 KB  |  54 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import gtk
  5. import gobject
  6. import sys
  7. import dbus
  8. import logging
  9. import ScreenResolution
  10. from ScreenResolution.policykit import PolicyKitAuthentication
  11. POLICY_KIT_ACTION = 'com.ubuntu.screenresolution.mechanism.dontzap'
  12. SERVICE_NAME = 'com.ubuntu.ScreenResolution.Mechanism'
  13. OBJECT_PATH = '/'
  14. INTERFACE_NAME = 'com.ubuntu.ScreenResolution.Mechanism'
  15. usage = 'python policy-dontzap.py --enable'
  16. import os
  17. import sys
  18.  
  19. def get_dontzap_service(widget = None):
  20.     '''
  21.     returns a dbus interface to the screenresolution mechanism
  22.     '''
  23.     policy_auth = PolicyKitAuthentication()
  24.     granted = policy_auth.obtain_authorization(POLICY_KIT_ACTION, widget)
  25.     logging.debug('granted = %s' % granted)
  26.     if not granted:
  27.         return None
  28.     service_object = dbus.SystemBus().get_object(SERVICE_NAME, OBJECT_PATH)
  29.     service = dbus.Interface(service_object, INTERFACE_NAME)
  30.     return service
  31.  
  32.  
  33. def main(enable):
  34.     if enable not in ('--enable', '--disable'):
  35.         logging.error('called with wrong arguments = %s' % str(enable))
  36.         return False
  37.     conf = get_dontzap_service()
  38.     if not conf:
  39.         logging.error('cannot connect to dbus service')
  40.         sys.exit(1)
  41.     
  42.     logging.debug('setting dontzap to %s' % enable)
  43.     exit_code = conf.setDontZap(enable)
  44.     logging.debug('exit status: %d' % exit_code)
  45.     return exit_code
  46.  
  47. if __name__ == '__main__':
  48.     if len(sys.argv) > 1:
  49.         operation_status = main(sys.argv[1])
  50.     else:
  51.         operation_status = 1
  52.     sys.exit(operation_status)
  53.  
  54.